//
//  Mail_GetUnReceiveCount.m
//  EpointFrame5
//
//  Created by Pill Gong on 14-2-13.
//  Copyright (c) 2014年 Epoint. All rights reserved.
//

#import "Mail_GetUnReceiveCount_Task.h"
#import "EpointStringUtil.h"

@implementation Mail_GetUnReceiveCount_Task

- (void)execute {
    NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
    NSString *ValidateData = [EpointBizTools getToken];
    NSString *url = self.getMobileOAWebserviceURL;
    NSString *wsNamespace = NSLocalizedString(@"Epoint_DNet_WS_NameSpace", @"");
    NSString *userguid = [userDefaults objectForKey:Epoint_User_UserGuid];
    
//    EpointWebServiceUtil *ws = [[EpointWebServiceUtil alloc]initWithUrl:url namespace:wsNamespace method:@"Mail_GetUnReceiveCount"];
    
    NSString *ParasXml = @"<![CDATA[<?xml version=\"1.0\" encoding=\"gb2312\"?><paras><UserGuid>%@</UserGuid></paras>]]>";
    ParasXml = [NSString stringWithFormat:ParasXml,userguid];
//    [ws addParameterForString:@"ValidateData" value:ValidateData];
//    [ws addParameterForString:@"ParasXml" value:ParasXml];
//    NSString *bs = ws.start;

//    if ([self validateXMLWS:bs]) {
//        //[self exeSuccessWithData:[self getLst:bs]];
//        NSString *unreadMailNum = [EpointStringUtil getXMLFormatedAttribute:bs :@"TotalNumCount"];
//        [self sendDataRefreshUI:@[@"1", unreadMailNum]];
//    }
    if (![self isNetWorkAvailable])
    {
        [self sendDataRefreshUI:@[@"1", @"0"]];
    }
    else
    {
        //请求接口
        EpointWebServiceUtil *ws = [[EpointWebServiceUtil alloc]initWithUrl:url namespace:wsNamespace method:@"Mail_GetUnReceiveCount"];
        [ws addParameterForString:@"ValidateData" value:ValidateData];
        [ws addParameterForString:@"ParasXml" value:ParasXml];
        NSString *bs =  ws.start;
        
        NSMutableArray *result = [self validateXMLWS2:bs];
        if ([[result objectAtIndex:0]isEqualToString:@"1"]) {
            NSString *unreadMailNum = [EpointStringUtil getXMLFormatedAttribute:bs :@"TotalNumCount"];
            [self sendDataRefreshUI:@[@"1", unreadMailNum]];
        }
        else
        {
            [self sendDataRefreshUI:@[@"1", @"0"]];
        }
    }
}

@end
